package com.bywlkjs.bygo.wechat.applet.spring.boot.entity;

import com.alibaba.fastjson.JSON;
import com.bywlkjs.bygo.wechat.applet.config.WechatAppletConfig;
import com.bywlkjs.bygo.wechat.applet.entity.AuthCode2SessionEntity;
import com.bywlkjs.common.util.AesCbcUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AppletUserInfoEntity extends com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity {

    @Resource
    WechatAppletConfig wechatAppletConfig;

    public static class Param extends com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.Param { }

    @Accessors(chain = true)
    @NoArgsConstructor
    @AllArgsConstructor
    @Service
    public static class UserInfoResult extends com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.UserInfoResult{

        @Resource
        private WechatAppletConfig wechatAppletConfig;

        @Override
        public com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.UserInfoResult analysis(com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.Param param){
            com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.UserInfoResult decrypt = com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.decrypt(wechatAppletConfig, param, com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.UserInfoResult.class);
            this.setUnionid(decrypt.getUnionid())
                    .setProvince(decrypt.getProvince())
                    .setOpenId(decrypt.getOpenId())
                    .setNickname(decrypt.getNickname())
                    .setErrcode(decrypt.getErrcode())
                    .setCountry(decrypt.getCountry())
                    .setCity(decrypt.getCity())
                    .setAvatarUrl(decrypt.getAvatarUrl())
                    .setErrmsg(decrypt.getErrmsg())
                    .setGender(decrypt.getGender());
            return this;
        }
    }

    @Accessors(chain = true)
    @NoArgsConstructor
    @AllArgsConstructor
    @Service
    public static class PhoneNumberResult extends com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.PhoneNumberResult {
        private String phoneNumber;
        private String purePhoneNumber;
        private String countryCode;


        @Resource
        private WechatAppletConfig wechatAppletConfig;

        @Override
        public com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.PhoneNumberResult analysis(com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.Param param){
            com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.PhoneNumberResult decrypt
                    = com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity
                    .decrypt(wechatAppletConfig, param, com.bywlkjs.bygo.wechat.applet.entity.AppletUserInfoEntity.PhoneNumberResult.class);
            this.setCountryCode(decrypt.getCountryCode())
                    .setPurePhoneNumber(decrypt.getPurePhoneNumber())
                    .setPhoneNumber(decrypt.getPhoneNumber());
            return this;
        }

    }

}
